<template>
    <div>
        <NavBar :title="title"></NavBar>
        <van-tabs v-model:active="active">
            <van-tab title="商品">
              <Swipe :images="images" :imgwidth="imgwidth" :imgheight="imgheight"></Swipe>

        <div v-for="item in detailApiData">
             <van-card
  :price="item.goods_price"
  :title="item.goods_name"
>
</van-card>
        </div>
       




            </van-tab>
            <van-tab title="详情">
                <div v-html="categoriesApiData.goods_introduce"></div>
                <van-action-bar>
                    <van-action-bar-icon icon="chat-o" text="客服" color="#ee0a24" />
                    <van-action-bar-icon icon="cart-o" text="购物车" :badge="store.counter.length"/>
                    <van-action-bar-icon icon="star" text="已收藏" color="#ff5000" badge="99+" />
                    <van-action-bar-button type="warning" text="加入购物车"  @click="goCart"/>
                    <van-action-bar-button type="danger" text="立即购买" />
                </van-action-bar>

            </van-tab>
            <van-tab title="评论">内容 3</van-tab>

        </van-tabs>
    </div>

</template>

<script setup>
import NavBar from '@/components/NavBar.vue';
const title = '商品详情'
import Swipe from '@/components/Swipe.vue';
const images = [
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg',
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg',
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-3.jpeg',
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-4.jpeg',
];
const imgwidth = '100%'
const imgheight = '200px'
import { useRoute,useRouter } from 'vue-router';
const route = useRoute()
const router = useRouter()
console.log(route.params.goods_id);

import { ref } from 'vue';
const categoriesApiData = ref([])
const detailApiData = ref([])
import { detailApi } from '@/api/api';
detailApi(route.params.goods_id).then(res => {
    console.log(res);
    categoriesApiData.value = res.data.message
    detailApiData.value = res.data
})

import { useCounterStore } from '@/stores/counter'
// 在组件内部的任何地方均可以访问变量 `store` ✨
const store = useCounterStore()
const goCart=()=>{
    store.counterAdd(categoriesApiData.value,route.params.goods_id)
    router.push('/home/gwc')
}
</script>

<style lang="scss" scoped></style>